#ifndef FILELOADER_H_
#define FILELOADER_H_

#include "NBT.h"

class Chunk;

class MinecraftFile
{
public:
	// Nice easy to set variable for buffer size (defaults to 32K)
	static unsigned int nDefaultBufferSize;

	// Default constructor/destructor
	MinecraftFile();
	~MinecraftFile();

	// Reads in the file and decompresses it, nothing more (Defaults gzip Buffer size to 128K)
	bool Load(const char *_szFileName, unsigned int _gzSize = 131072);

	// Decodes the file from binary to our Named Binary Tag (NBT) format
	void Decode();

	// decodes into a chunk object
	void DecodeIntoChunk(Chunk* _chunk);

	// Writes the NBT out to text (must decode first)
	void WriteToText(const char *_szFileName);

	// Deletes the internal NBT
	void CleanUpNBT();

	// Returns the internal NBT file
	const NBT::NBTFile *GetNBT() const { return m_pNBTFile; }

private:
	char *m_FileBuff;
	unsigned int m_nCurrentSize;
	unsigned int m_nFileSize;
	NBT::NBTFile *m_pNBTFile;

	// Doubles the size of the buffer and copys the data over
	void ResizeBuffer();

	// Deletes the internal file buffer
	void ClearBuffer();
};

#endif
